<template>
  <div id="login">
    <!-- <el-radio-group v-model="labelPosition" size="small">
      <el-radio-button label="left">左对齐</el-radio-button>
      <el-radio-button label="right">右对齐</el-radio-button>
      <el-radio-button label="top">顶部对齐</el-radio-button>
    </el-radio-group> -->
    <div class="login-wrapper">
        <div class="logo">
          <img width="150px" src="../../../public/images/logo.jpg" alt="">
          <span class="banktitle">蜗牛银行管理系统</span>
        </div>
        <div class="wrapper">
          <title>登录</title>
          <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
          <el-form-item label="用户名：">
            <el-input v-model="user.username"></el-input>
          </el-form-item>
          <el-form-item label="密码：">
            <el-input v-model="user.password"></el-input>
          </el-form-item>

          <div class="btn">
            <span @click="$router.push('/register')">没有账号，去注册</span>
            <button @click="login">登录</button>
            
          </div>
          
          
          
        </el-form>
        </div>
    </div>

  </div>
</template>

<script>
import axios from '../../http/axios'
import apis from '../../http/apis/apis'
export default {
    data() {
      return {
        labelPosition: 'right',
        user: {
          username: '',
          password: '',
        }
      };
    },
    methods: {
      async test() {
        const data = await axios({
          url:'/users/test'
        })
        console.log(data);
      },
      reset() {
        this.user.username = '',
        this.user.password = ''
      },
      async login() {
        // const {data} = await axios({
        //   url: '/users/login',
        //   method: 'post',
        //   data: {username: this.user.username, password: this.user.password}
        // })
        const {data} = await apis.users.login({username: this.user.username, password: this.user.password})
        if(data.status) {
          localStorage.token = data.token
          alert('登录成功')
          this.$router.push('/system')
        }else {
          alert('用户名或密码错误')
        }
      },
      
    }
    
  }
</script>

<style lang="scss">
  #login {
    height: 100%;
    background: linear-gradient(to right, #2A85ED,#36ECE1); 
    

    .login-wrapper{
      width: 700px;
      height: 350px;
      background-color: #fff;
      border-radius: 10px;
      overflow: hidden;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      align-content: center;
      justify-content: center;
      padding: 0 20px;
      .logo {
        display: flex;
        flex-direction: column;
        align-content: center;
        justify-content: center;
        img {
          box-shadow: 0px 0px 5px #ccc;
          border-radius: 50%;
        }
        .banktitle {
          font-size: 20px;
          color: #878E9D;
          margin-top: 20px;
        }
      }
      .wrapper {
        margin-left: 60px;
        width: 300px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .btn {
          display: flex;
          justify-content: flex-end;
          align-content: flex-end;
          button {
            margin-left: 30px;
            border-radius: 5px;
            border: none;
            outline: none;
            width: 150px;
            height: 40px;
            border: 1px solid #ccc;
            background: linear-gradient(to right, #2A85ED,#36ECE1); 
            color: #fff;
            cursor: pointer;
          }
          span {
            font-size: 12px;
            cursor: pointer;
          }
          
        }
      }
    }
  }
</style>